package game
{
	import flash.events.*;
	import flash.utils.Dictionary;
	
	import game.GlobalConfig;
	import game.model.GameData;
	import game.model.type.Enum;
	
	import morn.core.handlers.Handler;
	import morn.core.managers.ResLoader;
	/**加载活动动效资源**/
	public class LoadActivityEff
	{
		/**活动是否已经结束  true结束**/
		private var activityEndKey:Dictionary=new Dictionary;
		/**某个活动是否已经加载完成**/
		private var loadCompletedKey:Dictionary=new Dictionary;
		/**某项活动的资料列表**/
		private var resourceList:Dictionary=new Dictionary;
		/**某项活动的数据列表**/
		private var dataList:Dictionary=new Dictionary;
		/**是否正在动效 true是**/
		private var isToLoad:Boolean=false;
		
		protected static var cardata:GameData = new GameData();
		private static var nstance:LoadActivityEff;
		private static var isSingle:Boolean=false;
		public function LoadActivityEff()
		{
			if(!isSingle){
				throw new Error("error Single."); 
			}
		}
		
		public static function get instance():LoadActivityEff
		{
			if(nstance==null){
				isSingle=true;
				nstance=new LoadActivityEff;
				isSingle=false;
			}
			return nstance;
		}
		/**设置活动结束**/
		public function setEnd(key:String):void{
			if(this.activityEndKey[key]!=null){
				this.activityEndKey[key]=true;
			}
			
		}
		/**活动效果是否已经加载**/
		public function isLoadEff(key:String):Boolean{
			var b:Boolean=false;
			for(var ikey:String in loadCompletedKey){
				if(ikey==key){
					b=true;
					break;
				}
			}
			if(b){
				return this.loadCompletedKey[key];
			}else{
				return false
			}
		}
		/**
		 * key:活动标记
		 * rlist:资源列表
		 * cls:面板view
		 * data:数据
		 */
		public function loadChangeEff(key:String,rlist:Array,cls:*,data:*=null):void{
			var b:Boolean=false;
			for(var ikey:String in loadCompletedKey){
				if(ikey==key){
					b=true;
					break;
				}
			}
			if(!b){
				this.activityEndKey[key]=false;
				this.loadCompletedKey[key]=false;
				this.resourceList[key]=rlist;
				this.dataList[key]=[data];
			}else{
				if(this.loadCompletedKey[key]){
					return;
				}
				trace("LoadEff loadChangeEff 活动动效记录数据 ",key);
				this.dataList[key].push(data);
			}

			if(isToLoad)return;
			isToLoad=true;
			
			trace("LoadEff loadChangeEff 开始加载活动动效 ",key);
			var arr:Array = [];
			for(var i:int=0;i<rlist.length;i++){
				arr.push({url: rlist[i]+"?v="+GlobalConfig.version, type: ResLoader.SWF, size: 500});
			}
			ZooMain.loader.loadAssetUrlList(arr, new Handler(changEonComplete,[cls,key]),new Handler(changEonProgress));
		}
		
		private function changEonComplete(cls:*,key:String):void{
			this.loadCompletedKey[key]=true;
			this.isToLoad=false;
			trace("LoadEff changEonComplete 动效加载完成",key);
			//if(cardata.data_room.getStatus()<CarEnum.CAR_STATUS_DEAL){
				//ZooMain.view.showView(cls,this.dataList[key]);
			//}
			if(!this.activityEndKey[key]){
				ZooMain.view.showView(cls,this.dataList[key]);
			}

		}
		
		private function changEonProgress(value:int):void{
			
		}
	
		
	}
}